<template>
  <div>
    <div v-loading="loading" class="content px-3">
      <h5 class="text-primary">受理信息</h5>
      <div class="d-flex py-1">
        <div class="d-flex flex-1">
          <div class="item-w">客户名称：</div>
          <div>{{ relatedData.customer_name }}</div>
        </div>
        <div class="d-flex flex-1">
          <div class="item-w">项目地址：</div>
          <div class="flex-1">{{ relatedData.address }}</div>
        </div>
      </div>
      <div class="d-flex py-1">
        <div class="d-flex flex-1">
          <div class="item-w">负责人：</div>
          <div>{{ relatedData.corp_name || '-' }}</div>
        </div>
        <div class="d-flex flex-1">
          <div class="item-w">联系电话：</div>
          <div>{{ relatedData.mobile_no }}</div>
        </div>
      </div>
      <div class="d-flex py-1">
        <div class="d-flex flex-1">
          <div class="item-w">A角：</div>
          <div>{{ relatedData.res_a_name || '-' }}</div>
        </div>
        <div class="d-flex flex-1">
          <div class="item-w">B角：</div>
          <div>{{ relatedData.res_b_name || '-' }}</div>
        </div>
      </div>
      <div class="d-flex py-1">
        <div class="d-flex flex-1">
          <div class="item-w">申请金额:</div>
          <div>{{ relatedData.apply_funds || '-' }} 万元</div>
        </div>
        <div class="d-flex flex-1">
          <div class="item-w">申请年限：</div>
          <div>{{ relatedData.load_years || '-' }} 年</div>
        </div>
      </div>
      <h5 class="text-primary mt-3">立项信息</h5>
      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          建议金额：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.approved_funds || '-' }} 万元</span>
          <el-input
            v-else
            @change="submitKeyRelated('approved_funds')"
            v-model="editData.approved_funds"
            class="form-control-ml"
            v-input-number="{ min: 0, fixed: 2 }"
            placeholder="建议金额"
          >
            <span slot="append">万元</span>
          </el-input>
        </div>
      </div>
      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          贷款期限：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.months || '-' }} 月</span>
          <el-input
            v-else
            @change="submitKeyRelated('months')"
            v-model="editData.months"
            class="form-control-ml"
            v-input-number="{ min: 0, fixed: 0 }"
            placeholder="贷款期限"
          >
            <span slot="append">月</span>
          </el-input>
        </div>
      </div>
      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          担保产品：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.project_type_name || '-' }}</span>
          <select-credit-product
            v-else
            placeholder="请选择担保产品"
            v-model="editData.project_type_id"
            :select-params="isSYSTEM ? { 'agency_id.eq': relatedData.service_id } : {}"
            @change="setLoanMode"
            class="form-control-ml"
            :project-type="relatedData.gua_type"
          ></select-credit-product>
        </div>
      </div>
      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          贷款实际用途：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.funds_use_dir || '-' }}</span>
          <el-input
            v-else
            @change="submitKeyRelated('funds_use_dir')"
            v-model="editData.funds_use_dir"
            class="form-control-ml"
            placeholder="贷款实际用途"
          ></el-input>
        </div>
      </div>
      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          贷款银行：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.bank_name || '-' }}</span>
          <select-banks
            v-model="editData.bank_id"
            :project-type="relatedData.gua_type"
            @select="setPublicName"
            filterable
            v-else
            class="form-control-ml"
          ></select-banks>
        </div>
      </div>
      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          银行分险比例：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.bank_risk_rate || '-' }}%</span>
          <el-input
            v-else
            placeholder="银行分险比列"
            v-input-number="inputOptions"
            v-model="editData.bank_risk_rate"
            @change="bankRiskRateChange"
            class="form-control-ml"
          >
            <span slot="append">%</span>
          </el-input>
        </div>
      </div>

      <template v-if="isUnion || isUnionType">
        <div class="d-flex align-items-center py-2">
          <div class="item-label">
            <span v-if="!viewMode" class="text-danger">*</span>
            省农担分险比例：
          </div>
          <div class="flex-1">
            <span v-if="viewMode">{{ relatedData.join_risk_rate || '-' }}%</span>
            <el-input
              placeholder="省农担分险比例"
              v-else
              @change="submitKeyRelated('join_risk_rate')"
              v-input-number="inputOptions"
              v-model="editData.join_risk_rate"
              class="form-control-ml"
            >
              <span slot="append">%</span>
            </el-input>
            <div class="text-danger small" v-show="isNeq100 && !isUnionType">
              银行分险比例+担保公司分险比例不等于100%
            </div>
          </div>
        </div>
      </template>
      <template v-if="isUnionType">
        <div class="d-flex align-items-center py-2">
          <div class="item-label">
            <span v-if="!viewMode" class="text-danger">*</span>
            地方机构分险比例：
          </div>
          <div class="flex-1">
            <span v-if="viewMode">{{ relatedData.join_risk_rate_qx || '-' }}%</span>
            <el-input
              v-else
              placeholder="地方机构分险比例"
              v-input-number="inputOptions"
              @change="submitKeyRelated('join_risk_rate_qx')"
              v-model="editData.join_risk_rate_qx"
              class="form-control-ml"
            >
              <span slot="append">%</span>
            </el-input>
            <div class="text-danger small" v-show="isNeq100">
              银行分险比例+担保公司分险比例不等于100%
            </div>
          </div>
        </div>

        <div class="d-flex align-items-center py-2" v-if="isUnion">
          <div class="item-label">
            <span v-if="!viewMode" class="text-danger">*</span>
            地方联保机构：
          </div>
          <div class="flex-1">
            <span v-if="viewMode">{{ relatedData.gua_service_name || '-' }}</span>
            <select-credit
              :is-pro="true"
              clearable
              v-else
              class="form-control-ml"
              v-model="editData.gua_service_id"
              @select="setGuaServiceName"
              placeholder="地方机构"
            ></select-credit>
          </div>
        </div>
      </template>

      <div class="d-flex align-items-center py-2">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          是否林下经济：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">
            {{ { 1: '是', 0: '否' }[relatedData.is_offline_eco] || '-' }}
          </span>
          <c-radio-group
            v-else
            @change="submitKeyRelated('is_offline_eco')"
            v-model="editData.is_offline_eco"
            :options="{ 0: '否', 1: '是' }"
          ></c-radio-group>
        </div>
      </div>

      <div class="d-flex align-items-center py-2" v-if="!isPerson">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          上年度资产总额：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.assets_funds || '-' }} 万元</span>
          <el-input
            placeholder="上年度资产总额"
            v-else
            @change="submitKeyRelated('assets_funds')"
            v-input-number="{ min: 0, fixed: 2 }"
            v-model="editData.assets_funds"
            class="form-control-ml"
          >
            <span slot="append">万元</span>
          </el-input>
        </div>
      </div>
      <div class="d-flex" v-if="!viewMode && !isPerson">
        <div class="item-label"></div>
        <div class="flex-1">
          <small class="text-sm text-warning">
            企业必填(不能为0)，用于核算企业规模大型、中型、小型、微型
          </small>
        </div>
      </div>

      <div class="d-flex align-items-center py-2" v-if="!isPerson">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          上年度销售收入：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.sale_income || '-' }} 万元</span>
          <el-input
            placeholder="上年度销售收入"
            v-else
            @change="submitKeyRelated('sale_income')"
            v-input-number="{ min: 0, fixed: 2 }"
            v-model="editData.sale_income"
            class="form-control-ml"
          >
            <span slot="append">万元</span>
          </el-input>
        </div>
      </div>
      <div class="d-flex" v-if="!viewMode && !isPerson">
        <div class="item-label"></div>
        <div class="flex-1">
          <small class="text-sm text-warning">
            企业必填(不能为0)，用于核算企业规模大型、中型、小型、微型
          </small>
        </div>
      </div>
      <div class="d-flex align-items-center py-2" v-if="!isPerson">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          从业人数：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">{{ relatedData.emp_temp_total || '-' }}</span>
          <el-input
            placeholder="从业人数"
            v-else
            v-input-number="{ min: 0, fixed: 0 }"
            @change="submitKeyRelated('emp_temp_total')"
            v-model="editData.emp_temp_total"
            class="form-control-ml"
          >
            <span slot="append">人</span>
          </el-input>
        </div>
      </div>
      <div class="d-flex" v-if="!viewMode && !isPerson">
        <div class="item-label"></div>
        <div class="flex-1">
          <small class="text-sm text-warning">
            企业必填(不能为0)，用于核算企业规模大型、中型、小型、微型
          </small>
        </div>
      </div>

      <h5 class="text-primary py-2">资料补充</h5>
      <div>
        <attach-main
          ref="attachMain"
          :view-mode="viewMode"
          :related-id="queryId"
          @status="datumStatusChange"
          style="--tag-balel-width: 130px"
        ></attach-main>
      </div>
      <div class="d-flex align-items-center py-2" v-if="isReLetter">
        <div class="item-label">
          <span v-if="!viewMode" class="text-danger">*</span>
          签章时间：
        </div>
        <div class="flex-1">
          <span v-if="viewMode">
            {{ letterData.sign_date }}
          </span>
          <el-input
            v-else
            placeholder="签章时间"
            v-model="letterData.sign_date"
            class="form-control-ml"
          ></el-input>
        </div>
        <c-select
          :options="{
            0: '不盖章(客户线下签约时选择)',
            1: '加盖公章',
          }"
          :number-key="true"
          v-model="signStatus"
        ></c-select>
      </div>

      <div class="text-center mt-4" v-if="!viewMode">
        <el-button @click="handleSubmit" type="primary" :loading="submitLoading" class="btn-long">
          同意立项
        </el-button>
        <el-button
          @click="handleVisible"
          type="danger"
          :loading="submitLoading"
          v-if="dismiss"
          class="btn-long"
        >
          拒绝
        </el-button>
      </div>
    </div>

    <project-approve-refuse
      :visible.sync="desVisible"
      @success="handleClose"
      :query-id="queryId"
    ></project-approve-refuse>

    <el-dialog :visible.sync="fundsTipVisible" append-to-body title="风险提示">
      <span class="text-warning" v-if="inFunds <= 1000 || +relatedData.gua_type === 2">
        本次项目建议金额与该客户在保金额已合计超过300万元，请注意控制风险
      </span>
      <span class="text-danger" v-else>
        本次项目建议金额与该客户在保金额已合计超过1000万元，不能立项。
      </span>
      <c-table border :columns="tableColumns" :data="inProject" v-if="inProject.length"></c-table>
      <div class="text-center mt-4" v-if="inFunds <= 1000 || +relatedData.gua_type === 2">
        <el-button @click="submit" type="primary" :loading="submitLoading" class="btn-long">
          继续立项
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { nzhToMoney, sub, add } from '@vimi/utils-tool'
import SelectBanks from '@/credit/components/select/SelectOrgBank'
import ProjectApproveRefuse from '@/credit/views/city/program/ProjectApproveRefuse'
import SelectCreditProduct from '@/credit/components/select/SelectCreditProduct'
import AttachMain from '@/credit/views/city/bus/normal/item/AttachMain'
import SelectCredit from '@/credit/views/county/unionProvince/components/item/SelectCredit'
import { num } from '@/common/plugins/tools/format'
export default {
  components: {
    SelectBanks,
    ProjectApproveRefuse,
    SelectCreditProduct,
    AttachMain,
    SelectCredit,
  },
  props: {
    queryId: { type: String },
    viewMode: {
      type: Boolean,
      default: false,
    },
    isReLetter: { type: Boolean, default: false }, // 重做担保意向函
    dismiss: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      loading: false,
      submitLoading: false,
      desVisible: false,
      editData: {},
      inputOptions: {
        min: 0,
        max: 100,
        fixed: 2,
        onMin: () => this.$message.error('不能小于0'),
        onMax: () => this.$message.error('不能超过100'),
        onFixed: () => this.$message.error('小数点不能超过2位数'),
      },
      // riskRemark: initRisk(),
      // isDrection: initRisk(),
      // isWish: initRisk(),
      insuranceVisible: false,
      deviceVisible: false,
      relatedData: {},
      letterId: '',
      attachFinished: 0,
      attachVisible: false,
      letterData: {},

      inFunds: 0,
      inProject: [],
      tableColumns: [
        { attrs: { label: '贷款主体', prop: 'customer_name', align: 'center' } },
        { attrs: { label: '银行名称', prop: 'claim_bank_name', align: 'center' } },
        { attrs: { label: '在保金额', prop: 'warranty_amount', align: 'center' } },
        {
          attrs: { label: '放款日期', prop: 'load_date', align: 'center' },
          process: v => this.$utils.dateFormat(v, 'yyyy-MM-dd'),
        },
        {
          attrs: { label: '结束日期', prop: 'load_end_date', align: 'center' },
          process: v => this.$utils.dateFormat(v, 'yyyy-MM-dd'),
        },
      ],
      fundsTipVisible: false,
      signStatus: 1,
    }
  },
  computed: {
    ...mapGetters(['org', 'user', 'userId', 'clientId']),
    noVaildtorFunds() {
      return num(this.relatedData.renewal_type) > 1
    },
    isUnion() {
      return this.user?.scopeArr?.includes('dirGuaPro') ?? false
    },
    rejectName() {
      return this.org.orgName + '-' + this.user.realName
    },
    guaType() {
      return +this.relatedData.gua_type
    },
    isPerson() {
      return +this.relatedData.customer_type === 2
    },
    isProSelf() {
      return +this.relatedData.is_pro_dir === 1
    },
    riskTotal() {
      return Math.round(this.editData.join_risk_rate * this.unionRisk * 100) / 10000
    },
    unionRisk() {
      return sub(100, this.editData.bank_risk_rate)
    },
    isUnionType() {
      return [1, 4].includes(this.guaType) && !this.isProSelf
    },
    isSYSTEM() {
      // 系统后台查所有
      return this.org.orgClass === 'org_credit_sys'
    },
    // itemReturnPlan() {
    //   return `1、还款方式：${this.replayInfo.method}
    //    2、还款计划：${this.replayInfo.plan}
    //    3、还款来源：${this.replayInfo.suource}`
    // },
    farmId() {
      return this.relatedData.customer_id
    },
    isNeq100() {
      if (+this.editData.bank_risk_rate && +this.editData.join_risk_rate) {
        return (
          add(
            this.editData.bank_risk_rate,
            this.editData.join_risk_rate,
            this.editData.join_risk_rate_qx
          ) !== 100
        )
      }
      return false
    },

    // // 是否已经完善立项附件
    // attachFinished() {
    //   return +this.relatedData.datum_status === 1
    // },
    isOnlineSign() {
      return +this.relatedData.is_online_sign === 1
    },
  },
  watch: {
    queryId: {
      handler: function () {
        this.getRelatedData()
      },
      immediate: true,
    },
  },
  mounted() {},
  created() {},
  methods: {
    submitKeyRelated(key) {
      const data = {}
      if (typeof key === 'string') {
        data[key] = this.editData[key] || null
      } else {
        key.forEach(item => {
          data[item] = this.editData[item] || null
        })
      }
      this.$api.updateData(this.$serviceName, 'customer_related', this.queryId, data)
    },
    setGuaServiceName(service) {
      this.editData.gua_service_name = service?.agency_name ?? ''
      this.submitKeyRelated(['gua_service_id', 'gua_service_name'])
    },
    bankRiskRateChange() {
      if (this.isProSelf) {
        this.editData.join_risk_rate = sub(100, this.editData.bank_risk_rate)
      }
      this.submitKeyRelated('bank_risk_rate')
    },
    sendLetter() {
      const data = {
        gua_org_id: +this.guaType === 4 ? this.relatedData.recommend_service : this.clientId,
        ele_letter_type: 1,
        customer_related_id: this.queryId,
        bear_rate: sub(100, this.editData.bank_risk_rate),
        sign_date: this.$utils.dateFormat(new Date(), 'yyyy年MM月dd日'),
        bank_name: this.editData.bank_name,
        customer_name: this.relatedData.customer_name,
        apply_funds: this.editData.approved_funds,
        apply_funds_capital: nzhToMoney(this.editData.approved_funds * 10000),
        load_years: this.editData.months,
        funds_use_dir: this.editData.funds_use_dir,
        submit_person_name: this.user.realName,
      }
      if (!this.letterId) {
        return this.$api
          .addData(this.$serviceName, 'ele_letter_info', data)
          .then(() => {
            this.getEletter()
          })
          .catch(() => this.$message.error('生成担保意向函失败'))
      } else {
        if (this.isReLetter) {
          data.sign_date = this.letterData.sign_date
          data.sign_status = this.signStatus || '0'
          return this.$api.updateData(this.$serviceName, 'ele_letter_info', this.letterId, data)
        } else if (+this.letterData.sign_status > 0) {
          return Promise.resolve()
        } else {
          return this.$api.updateData(this.$serviceName, 'ele_letter_info', this.letterId, data)
        }
      }
    },
    getEletter() {
      this.$api
        .getData(
          this.$serviceName,
          'ele_letter_info',
          {
            'customer_related_id.eq': this.queryId,
            'ele_letter_type.eq': 1,
          },
          { create_time: 'desc' }
        )
        .then(res => {
          const data = res?.data?.[0] ?? {}
          this.letterData = data
          this.letterId = data.ele_letter_info_id
          this.letterData.sign_date =
            this.letterData.sign_date || this.$utils.dateFormat(new Date(), 'yyyy年MM月dd日')
        })
    },
    getRelatedData(byHander) {
      if (!this.queryId || this.loading) {
        return
      }
      this.relatedData = {}
      this.editData = {}
      const params = {
        'customer_related_id.eq': this.queryId,
      }
      this.loading = true
      this.$api
        .getData(this.$serviceName, 'customer_related', params, { create_time: 'desc' })
        .then(res => {
          this.relatedData = res?.data?.[0] ?? {}
          this.editData = { ...this.relatedData }
          this.editData.approved_funds =
            +this.editData.approved_funds || +this.editData.apply_funds || ''
          this.editData.months = +this.editData.months || +this.editData.load_years * 12 || ''
          this.getEletter()

          // 刷新附件内容
          byHander && this.$refs.attachMain?.getData()
        })
        .catch(() => {
          this.$message.error('请求项目基本信息失败')
        })
        .finally(() => {
          this.loading = false
        })
    },
    // handleAttachSuccess(res) {
    //   this.$emit('attach-success', res)
    // },
    datumStatusChange(status) {
      this.attachFinished = status
    },
    handleDetail(key) {
      switch (+key) {
        case 2:
          this.insuranceVisible = true
          break
        case 3:
          this.deviceVisible = true
          break
        default:
          break
      }
    },
    setLoanMode(value, select) {
      // this.getRiskData(value)
      this.editData.project_type_name = select.load_name || ''
    },
    setPublicName(bank) {
      this.editData.bank_type = bank.agency_type_sub || ''
      this.editData.bank_name = bank.agency_name || ''
      this.submitKeyRelated(['bank_id', 'bank_name', 'bank_type'])
    },
    handleClose() {
      this.beforeClose()
      this.$emit('success', true)
    },
    beforeClose() {
      this.$emit('close', false)
    },

    handleSubmit() {
      // 立项资料要件
      if (!this.attachFinished) {
        return this.$message.error('请先完善附件资料')
      }

      if (!+this.editData.approved_funds) {
        return this.$message.warning('请输入建议金额')
      }
      if (!+this.editData.months) {
        return this.$message.warning('请输入贷款期限')
      }
      if (!this.editData.project_type_id) {
        return this.$message.warning('请选择担保产品')
      }
      if (!this.editData.funds_use_dir) {
        return this.$message.warning('请输入贷款实际用途')
      }
      // if (!this.editData.res_user_id_risk_point) {
      //   return this.$message.warning('请选择风控员')
      // }
      if (!this.editData.bank_id) {
        return this.$message.warning('请选择贷款银行')
      }
      if (!this.editData.bank_risk_rate) {
        return this.$message.warning('请输入银行分险比列')
      }
      if (!this.editData.join_risk_rate) {
        return this.$message.warning('请输入担保分险比例')
      }
      if (!+this.editData.assets_funds && !this.isPerson) {
        return this.$message.warning('请输入上年度资产总额，不能为0')
      }
      if (!+this.editData.sale_income && !this.isPerson) {
        return this.$message.warning('请输入上年度销售收入，不能为0')
      }
      if (!+this.editData.emp_temp_total && !this.isPerson) {
        return this.$message.warning('请输入从业人数，不能为0')
      }
      if (this.isUnionType && !this.editData.join_risk_rate_qx) {
        return this.$message.warning('请输入地方分险比例')
      }
      if (this.isUnionType && this.isUnion && !this.editData.gua_service_id) {
        return this.$message.warning('请选择地方机构')
      }
      if (this.isNeq100) {
        this.$message.warning('银行分险比例+担保公司分险比例不等于100%')
        return false
      }
      if (this.noVaildtorFunds) {
        this.submit()
        return
      }
      this.inProject = []
      const params =
        +this.relatedData.customer_type === 1
          ? {
              'register_no.eq': this.relatedData.register_no,
            }
          : {
              'lender_idcard.eq': this.relatedData.lender_idcard,
            }
      this.submitLoading = true
      this.$api
        .getData(this.$serviceName, 'customer_left_funds_view_28', {
          ...params,
          isBIQuery: 1,
          'customer_related_id.neq': this.queryId,
        })
        .then(res => {
          this.submitLoading = false
          const data = res.data ?? []
          this.inProject = data
          const funds = data.reduce((num, item) => {
            num += +(item.warranty_amount || '')
            return num
          }, 0)
          this.inFunds = add(funds, this.editData.approved_funds)
          if (this.inFunds > 300) {
            this.fundsTipVisible = true
          } else {
            this.submit()
          }
        })
    },

    submit() {
      const dateNow = this.$utils.dateFormat(new Date())
      const data = {
        bank_id: this.editData.bank_id || '',
        bank_name: this.editData.bank_name,
        bank_type: this.editData.bank_type,
        months: this.editData.months,
        // item_confuse_des: '',
        approved_funds: this.editData.approved_funds,
        funds_use_dir: this.editData.funds_use_dir,
        project_type_id: this.editData.project_type_id,
        project_type_name: this.editData.project_type_name,
        gua_type: this.editData.gua_type,
        service_id: this.editData.service_id,
        recommend_service: this.editData.recommend_service,
        process_status: 1,
        join_risk_rate: this.editData.join_risk_rate,
        join_risk_rate_qx: !this.isUnionType ? 0 : this.editData.join_risk_rate_qx,
        bank_risk_rate: this.editData.bank_risk_rate,
        gua_service_id: this.editData.gua_service_id,
        gua_service_name: this.editData.gua_service_name,
        is_offline_eco: this.editData.is_offline_eco,
        assets_funds: this.editData.assets_funds,
        sale_income: this.editData.sale_income,
        emp_temp_total: this.editData.emp_temp_total,
      }
      if (+this.relatedData.item_status !== 1) {
        data.item_status = 1 // 状态 修改不传，否则会触发项目调查
        data.item_date = dateNow
        data.item_person = this.userId
      }
      this.submitLoading = true
      this.$api
        .updateData(
          this.$serviceName,
          'customer_related',
          this.relatedData.customer_related_id,
          data
        )
        .then(() => {
          this.fundsTipVisible = false
          this.$emit('success', true)
          this.$message.success('立项成功')
          this.sendLetter()
          this.beforeClose()
        })
        .catch(err => {
          this.$message.error(err?.data?.error_description || `操作失败，请重试！`)
        })
        .finally(() => {
          this.submitLoading = false
        })
    },
    handleVisible() {
      this.desVisible = true
    },
  },
}
</script>
<style lang="scss" scoped>
.table-bordered thead {
  border-bottom: 1px solid $border-color;
}
.item-w {
  width: 130px;
}
.item-label {
  width: 130px;
  padding: 5px 1px;
}
.content {
  margin: 0 auto;
}
</style>
